<template>
    <div>
      <el-col :span="6">
        <el-form ref="form" :rules="rules" :model="form" label-width="100px">
          <el-form-item label="规则名称" prop="name">
            <el-input v-model="form.name" placeholder="请输入规则名称"></el-input>
          </el-form-item>
          <el-form-item label="支持数" prop="number">
            <el-input v-model.number="form.number"></el-input>
          </el-form-item>
          <el-form-item label="消耗积分" prop="integral">
            <el-input v-model.number="form.integral"></el-input>
          </el-form-item>
          <el-form-item label="能否抽奖" prop="canDraw">
            <el-radio-group v-model="form.canDraw">
              <el-radio label="1">可以抽奖</el-radio>
              <el-radio label="0">不能抽奖</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="支持规则" prop="isAdd">
            <el-radio-group v-model="form.isAdd">
              <el-radio label="1">增加支持</el-radio>
              <el-radio label="0">减少支持</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="onSubmit">立即创建</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </div>
</template>

<script>
  export default {
    name: 'SupportRule',
    data() {
      return {
        form: {
          name: '',
          number: 1,
          integral: 0,
          canDraw: '1',
          isAdd: '1',
        },
        rules: {
          name: [
            { required: true, message: '请输入规则名称', trigger: 'blur' }
          ],
          number: [
            { required: true, message: '请输入每次变动支持数', trigger: 'change' }
          ],
          integral: [
            {  required: true, message: '请输入每次消耗积分数', trigger: 'change' }
          ]
        }
      }
    },
    methods: {
      onSubmit() {
        this.$refs.form.validate((valid) => {
          if (valid){

            this.getAxios('/boardSupportRule/insert',{
              title:this.form.name,
              supportNum:this.form.number,
              integral:this.form.integral,
              isAdd:this.form.isAdd,
              canDraw:this.form.canDraw
            }).then(res => {
              this.$message({
                type: 'success',
                message: '新增成功!'
              });
              this.name = ''
            }).catch(error => {
              this.$message({
                type: 'info',
                message: error.msg
              });
            })
          } else {
            return false;
          }
        })
      }
    }
  }
</script>





<style scoped>

</style>
